package jmine.tec.web.front.workflow;

import jmine.tec.web.front.dao.BackOfficeRequestStatusSystemIdentifier;

/**
 * Represents one request status with the transitions for the case of authorization or rejection. It could be a leaf (without the
 * transitions) or not.
 * 
 * @author wagner.tsuchiya
 */
public class BackOfficeRequestStatusVertex {
    private final BackOfficeRequestStatusSystemIdentifier status;

    private BackOfficeRequestStatusEdge authorizationEdge;

    private BackOfficeRequestStatusEdge rejectionEdge;

    /**
     * @return the status
     */
    public BackOfficeRequestStatusSystemIdentifier getStatus() {
        return this.status;
    }

    /**
     * @return the authorizationEdge
     */
    public BackOfficeRequestStatusEdge getAuthorizationEdge() {
        return this.authorizationEdge;
    }

    /**
     * @return the rejectionEdge
     */
    public BackOfficeRequestStatusEdge getRejectionEdge() {
        return this.rejectionEdge;
    }

    /**
     * Returns if this is a leaf
     * 
     * @return {@link Boolean}
     */
    public boolean isLeaf() {
        return this.authorizationEdge == null && this.rejectionEdge == null;
    }

    /**
     * Constructor that creates a non leaf vertex.
     * 
     * @param status status.
     * @param authorizationEdge authorizationEdge
     * @param rejectionEdge rejectionEdge
     */
    public BackOfficeRequestStatusVertex(BackOfficeRequestStatusSystemIdentifier status, BackOfficeRequestStatusEdge authorizationEdge,
            BackOfficeRequestStatusEdge rejectionEdge) {
        super();
        this.status = status;
        this.authorizationEdge = authorizationEdge;
        this.authorizationEdge.setFrom(this);
        this.rejectionEdge = rejectionEdge;
        this.rejectionEdge.setFrom(this);
    }

    /**
     * Constructor that creates a leaf vertex.
     * 
     * @param status status.
     */
    public BackOfficeRequestStatusVertex(BackOfficeRequestStatusSystemIdentifier status) {
        super();
        this.status = status;
        this.authorizationEdge = null;
        this.rejectionEdge = null;
    }

    /**
     * @param newAuthorizationEdge the authorization edge to set
     * @param newRejectionEdge the rejection edge to set
     */
    public void setEdges(BackOfficeRequestStatusEdge newAuthorizationEdge, BackOfficeRequestStatusEdge newRejectionEdge) {
        this.authorizationEdge = newAuthorizationEdge;
        this.authorizationEdge.setFrom(this);
        this.rejectionEdge = newRejectionEdge;
        this.rejectionEdge.setFrom(this);
    }
}
